package com.openingedu.mba.screen.activity.practice;

import java.sql.SQLException;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.lurencun.android.support.ui.BackUIActivity;
import com.lurencun.android.toolkit.util.ActivitySwitcher;
import com.openingedu.mba.R;
import com.openingedu.mba.common.AppSetting;
import com.openingedu.mba.common.CommConsts;
import com.openingedu.mba.persist.DbFaultQuestion;
import com.openingedu.mba.service.PracticeService;

/**
 * 
 * 练习历史记录
 * @author unidw
 *
 */
public class FaultQuestionActivity extends BackUIActivity {

	private Context mContext;
	private PracticeService practiceService;
	private String title;
	private List<DbFaultQuestion> questionList;
	private Button faultBtn;
	@Override
	protected void onCreateEx(Bundle savedInstanceState) {
		mContext = this;
		practiceService = new PracticeService();
		Intent intent = getIntent();
		title = intent.getStringExtra(AppSetting.MENU_TITLE);
		// 设置标题
		TextView titleView = (TextView) findViewById(R.id.app_title);
		titleView.setText(title);
		try {
			questionList = practiceService.listFaultQuestion(mContext);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		faultBtn = (Button) findViewById(R.id.fault_btn);
		TextView faultContent = (TextView) findViewById(R.id.fault_content);
		
		String text = String.format(getString(R.string.str_fault_question_desc), questionList.size() + "");
		faultContent.setText(text);
		
		faultBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String[] keys = new String[] { AppSetting.PRACTICE_WAY, AppSetting.MENU_TITLE };
				Object[] vals = new Object[] { CommConsts.Practice.FAULT_WAY, "错题练习" };
				ActivitySwitcher.switchTo(FaultQuestionActivity.this, CommonPraticeActivity.class, keys, vals);
			}
		});
	}
	
	@Override
	protected int getBackButtonResId() {
		return R.id.back_button;
	}

	@Override
	protected int getContentViewLayoutId() {
		return R.layout.fault_question;
	}

	@Override
	protected boolean isConfirmBack() {
		return false;
	}

}
